package com.dahua.db;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class DownloadInfo {
    private long id;
    private Context context;
    private boolean downloading;
    private long startTime;


    private final static String TABLE_NAME = "downloadInfo";
    private final static String KEY_ID = "id";
    private final static String KEY_DOWNLOADING = "downloading";
    private final static String KEY_START_TIME = "startTime";

    public DownloadInfo(Context context) {
        this.context = context;
    }

    public void saveData() {
        SharedPreferences sharedPreferences = context.getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();//获取编辑器
        editor.putLong(KEY_ID, id);
        editor.putBoolean(KEY_DOWNLOADING, downloading);
        editor.putLong(KEY_START_TIME, startTime);
        editor.commit();//提交修改
    }

    public DownloadInfo loadData() {
        SharedPreferences sharedPreferences = context.getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        id = sharedPreferences.getLong(KEY_ID, -1);
        downloading = sharedPreferences.getBoolean(KEY_DOWNLOADING, false);
        startTime = sharedPreferences.getLong(KEY_START_TIME, 0);
        return this;
    }

    public long getId() {
        return id;
    }

    public DownloadInfo setId(long id) {
        this.id = id;
        return this;
    }

    public boolean isDownloading() {
        return downloading;
    }

    public DownloadInfo setDownloading(boolean downloading) {
        this.downloading = downloading;
        return this;
    }


    public long getStartTime() {
        return startTime;
    }

    public DownloadInfo setStartTime(long startTime) {
        this.startTime = startTime;
        return this;
    }
}
